﻿using FireChat.Server.Database.Manager;
using FireChat.Server.Database.Table.Accounts;
using FireChat.Server.Session.Receiver;
using FireChat.Share.Web.Actions;
using FireChat.Share.Web.Model.Enums;
using FireChat.Share.Web.Model.Query.Contacts;
using FireChat.Share.Web.Package;

namespace FireChat.Server.Session.Actions.Concrete;


/// <summary>
/// 同意好友申请
/// </summary>
internal class AgreeFriendApplyAction : ServerAction<AgreeFriendApplyQuery>
{
    public override ServertActions Type => ServertActions.ArgeeFriendApply;

    protected override ServerPackage ActionExcute(PackageReceiver receiver, AgreeFriendApplyQuery query)
    {
        if (AccountManager.GetInstanceByName(query.Username) is not AccountData data)
        {
            return receiver.ReplyFailureAsync("目标不存在");
        }

        return receiver.AgreeContactApply(data.Id, AccountType.Account);
    }
}
